package net.brucecooper.mindmapgadget.client;

import net.brucecooper.mindmap.client.MindMap;
import net.brucecooper.mindmap.client.NodeDataStore;
import net.brucecooper.mindmap.client.SizeChangeCallback;

import org.cobogw.gwt.waveapi.gadget.client.NeedsWave;
import org.cobogw.gwt.waveapi.gadget.client.WaveFeature;

import com.google.gwt.gadgets.client.DynamicHeightFeature;
import com.google.gwt.gadgets.client.Gadget;
import com.google.gwt.gadgets.client.NeedsDynamicHeight;
import com.google.gwt.gadgets.client.UserPreferences;
import com.google.gwt.gadgets.client.Gadget.InjectContent;
import com.google.gwt.gadgets.client.Gadget.ModulePrefs;
import com.google.gwt.user.client.ui.RootPanel;

@ModulePrefs(title = "MindMap", author = "The Crimson Cactus", author_email = "bruce@crimsoncactus.net", author_link="http://www.brucecooper.net")
@InjectContent(files = "mindmap.css")
public class MindMapGadget extends Gadget<UserPreferences> implements NeedsWave, NeedsDynamicHeight {
	private WaveFeature wave;
	private DynamicHeightFeature dynHeight;

	MindMap comp;

	@Override
	protected void init(UserPreferences preferences) {
		NodeDataStore nds = new WaveNodeStore(wave);
		comp = new MindMap(nds);

		comp.addSizeChangeListener(new SizeChangeCallback() {
			public void sizeMayHaveChanged() {
				dynHeight.adjustHeight();
			}
		});
        comp.setUserInfoFetcher(new WaveUserInfoFetcher());
		

		RootPanel.get().add(comp);
		dynHeight.adjustHeight();
	}

	/**
	 * The Gadget API will inject the wave object, which can be used for access.
	 */
	public void initializeFeature(WaveFeature feature) {
		wave = feature;
	}


	/**
	 * The Gadget API will inject the wave object, which can be used for access.
	 */
	public void initializeFeature(DynamicHeightFeature feature) {
		dynHeight = feature;
	}

}
